package com.gues.controller;

import com.gues.eneity.Article;
import com.gues.eneity.Tag;
import com.gues.service.ArticleService;
import com.gues.service.TagService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class HomeController {

    @Resource
    ArticleService articleService;

    @Resource
    TagService tagService;

    @GetMapping("/articleList")
    public @ResponseBody List<Article> getArticleList() {
        return articleService.getArticleList();
    }

    @GetMapping("/article/{id}")
    public String article(@PathVariable("id") Integer id, Model model) {
        Article article = articleService.getArticleById(id);
        model.addAttribute("art", article);
        return "article";
    }

    @GetMapping("/getAllTags")
    public @ResponseBody List<Tag> getAllTags() {
        return tagService.getAllTags();
    }
}
